package com.zx.wangyixinwen.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.zx.wangyixinwen.MyRequestQueue;
import com.zx.wangyixinwen.R;
import com.zx.wangyixinwen.bean.Woman;

import java.util.List;

/**
 * Created by dllo on 16/1/22.
 */
public class WomanAdapter extends BaseAdapter {
    private List<Woman> datas;
    private Context context;

    public WomanAdapter(List<Woman> datas, Context context) {
        this.datas = datas;
        this.context = context;
    }

    @Override
    public int getCount() {
        return datas.get(0).getData().getArticle().size();
    }

    @Override
    public Object getItem(int position) {
        return datas.size() > 0 && datas != null ? datas.size() : 0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_woman_adapter, null);
            holder = new ViewHolder();
            holder.iv = (NetworkImageView) convertView.findViewById(R.id.iv_woman_adapter);
            holder.tv = (TextView) convertView.findViewById(R.id.tv_woman_adapter);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
//        holder.iv.setDefaultImageResId(R.mipmap.refresh);
        MyRequestQueue.setNetImage(holder.iv, datas.get(0).getData().getArticle().get(position).getImage().get(0).getUrl());
//        holder.tv.setText(datas.get(0).getData().getArticle().get(position).getTitle();
        holder.tv.setText(datas.get(0).getData().getArticle().get(position).getTitle());
        return convertView;
    }

    class ViewHolder {
        TextView tv;
        NetworkImageView iv;
    }
}
